package com.medicine.ecg.controller;

import com.medicine.ecg.service.PatientService;

import com.medicine.pojo.Element;
import com.medicine.pojo.Patient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author ChenJie
 * @date 2021/5/24
 */

@RequestMapping("/patient")
@RestController
@Api(value = "PatientController", tags = "患者信息的接口")
public class PatientController {

    @Autowired
    private PatientService patientService;

    /**
     * 根据患者ID获取患者个人信息
     * @param map 请求信息
     * @return 患者个人信息
     */
    @ApiOperation(value = "查询患者个人信息", notes = "按照ID查询患者信息")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者ID")
    @PostMapping("/id")
    public Patient queryPatientById(@RequestBody Map<String,Integer> map){
//        int i = 1;
        return patientService.getPatientById(map.get("id"));
    }

    @ApiOperation(value = "查询患者个人信息", notes = "按照name查询患者信息")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者name")
    @PostMapping("/name")
    public List<Patient> queryPatientByName(@RequestBody Map<String,String> map){
        return patientService.getPatientByName(map.get("name"));
    }

    @ApiOperation(value = "查询患者列表", notes = "查询所有患者信息")
    @GetMapping("/queryPatientList")
    public List<Patient> queryPatientList(){
        return patientService.getPatientList();
    }

    /**
     * TODO:此处需要注意心电数据是需要按分段号聚合，换句话说，不仅只是将ecg表中的同一个pid下的所有心电数据查询出来这么简单
     *      而是，将同一个pid下的所有心电数据取出后，按segment段号返回（pid->Patient,map<String,List<electrocardios>>）
     */

    @ApiOperation(value = "查询患者详情", notes = "按照ID查询患者详情(含心电坐标)")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者ID")
    @PostMapping("/queryInfo")
    public  Patient queryPatientInfoById(@RequestBody Map<String ,Integer> map)  {
        return patientService.getPatientInfoById(map.get("id"));

    }


    @ApiOperation(value = "查询患者异常信息", notes = "按照id查询患者异常心电图")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者ID")
    @PostMapping("/ecpInfo")
    public List<Map<String , Object>> queryEcgExceptionById(@RequestBody Map<String,Integer> map){
        return patientService.getEcgExceptionById(map.get("id"));
    }



    @ApiOperation(value = "查询患者心电图", notes = "按照id查询患者心电图")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者ID")
    @PostMapping("/ecgInfo")
    public List<Map<String , Object>> queryEcgInfoById(@RequestBody Map<String ,Integer> map){

        return patientService.getEcgInfoById(map.get("id"));
    }

    @ApiOperation(value = "显示患者详情", notes = "默认显示id为1的患者")
    @PostMapping("/default")
    @ResponseBody
    public Patient queryEcgInfo(){

        return patientService.getEcgInfo();
    }
    @ApiOperation(value = "显示患者诊断结果", notes = "默认显示id为1的诊断结果")
    @PostMapping("/defaultResult")
    @ResponseBody
    public Map<String,Object> queryResult(){
        return patientService.getEcgResult();
    }

    @ApiOperation(value = "查询患者诊断结果", notes = "按照id查询患者诊断结果")
    @ApiImplicitParam(name = "map", value = "封装到map中的患者ID")
    @PostMapping("/result")
    public Map<String,Object> queryEcgDiagnosis(@RequestBody Map<String ,Integer> map){
        return patientService.getEcgDiagnosis(map.get("id"));
    }

    @ApiOperation(value = "查询element信息", notes = "查询所有element中的信息")
    @GetMapping("/getElementInfo")
    public List<Element> queryElementInfo(){
        return patientService.getElementInfo();
    }


}

